<template>
    <div class="con">
        <div class="tip">
            <p>
                <span>验证银行绑定手机号</span>
                <br>
                请输入手机{{data.phone}}收到的短信验证码
            </p>
        </div>
        <div class="yzm">
            <p>
                <button @click="send()" id="yzm">获取验证码</button>
            </p>

            <input type="text" placeholder="请输入验证码" v-model="authCode">
        </div>

        <div class="btn" @click="ok()">
            <button>验证并执行</button>
        </div>
    </div>
</template>

<script>
export default {
    name: "tradecheck",
    data() {
        return {
            authCode: "",
            timestamp: "",
            data: {}
        };
    },

    methods: {
        send() {
            var yzm = document.getElementById("yzm");

            var clock = "";
            var nums = 60;
            yzm.disabled = true; //将按钮置为不可点击
            yzm.style.opacity = "0.5";
            yzm.innerHTML = nums + "s";
            clock = setInterval(doLoop, 1000); //一秒执行一次
            function doLoop() {
                nums--;
                if (nums > 0) {
                    yzm.innerHTML = nums + "s";
                } else {
                    clearInterval(clock); //清除js定时器
                    yzm.disabled = false;
                    yzm.style.opacity = "1";

                    yzm.innerHTML = "获取验证码";
                    nums = 60; //重置时间
                }
            }
            this.axios({
                method: "post",
                url: `${
                    this.siteUrl
                }/app/account/repay/applyBindCard?appid=web.2019&format=json&timestamp=${
                    this.timestamp
                }`,
                data: {
                    userId: localStorage.getItem("userId"),
                    cardNo: localStorage.getItem("xyaccountNo"),
                    bankId: this.data.bankId,
                    phone: this.data.phone,
                    cvv2: this.data.cvv2,
                    expireTime: this.data.expireTime,
                    bankName: localStorage.getItem("xybankName"),
                    accountName: localStorage.getItem("accountName"),
                    idNumber: localStorage.getItem("idNumber"),
                    payChannelId: this.data.payChannelId
                }
            })
                .then(response => {
                    console.log(response);
                    if (response.data.success == 1) {
                        this.$toast(response.data.message);
                    } else {
                        this.$toast(response.data.message);
                    }
                })
                .catch(error => {
                    console.log(error);
                    this.$toast("连接服务器异常");
                });
        },
        ok() {
            this.axios({
                method: "post",
                url: `${
                    this.siteUrl
                }/app/account/repay/conformBindCard?appid=web.2019&format=json&timestamp=${
                    this.timestamp
                }`,
                data: {
                    cvv2: this.data.cvv2,
                    repayOrderNo: this.data.repayOrderNo,
                    payChannelId: this.data.payChannelId,
                    accountNo: this.data.accountNo,
                    bankId: this.data.bankId,
                    cardId: localStorage.getItem("xycardId"),
                    userId: localStorage.getItem("userId"),
                    phone: this.data.phone,
                    authCode: this.authCode,
                    expireTime: this.data.expireTime
                }
            })
                .then(response => {
                    console.log(response);
                    if (response.data.success == 1) {
                        this.$toast("还款执行中");
                        this.$router.push({ name: "my" });
                    } else {
                        this.$toast(response.data.message);
                    }
                })
                .catch(error => {
                    console.log(error);
                    this.$toast("连接服务器异常");
                });
        }
    },
    mounted() {
        this.timestamp = Date.parse(new Date());
        this.data = this.$route.params.data;
        console.log(this.data);
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.con {
    width: 100%;
    min-height: 100vh;
    background: #fff;
}
.tip {
    overflow: hidden;
}
.tip p {
    color: #a6a9b5;
    font-weight: 200;
    text-align: center;
    font-size: 14px;
    line-height: 22px;
    margin-top: 39px;
}
.tip p span {
    color: #2d3659;
    font-size: 16px;
    font-weight: 400;
}
.yzm p {
    text-align: center;
    margin-top: 40px;
    color: #ffae4e;
}
.yzm p button {
    background: transparent;
}
.yzm input {
    height: 60px;
    font-size: 24px;
    width: 60%;
    margin-left: 20%;
    border-bottom: 1px solid #ececec;
    text-align: center;
}
input::-webkit-input-placeholder {
    color: #e9eaee;
    font-size: 24px;
}

.btn {
    width: 70%;
    height: 48px;
    line-height: 48px;
    background: #ffae4e;
    text-align: center;
    border-radius: 25px;
    margin-left: 15%;
    margin-top: 50px;
}
.btn button {
    width: 100%;
    font-size: 17px;
    color: #fff;
    background: transparent;
}
</style>
